<?
class injury extends module {

    // Author: Herman Tolentino MD
    // CHITS Project 2004

    function injury() {
        //
        // do not forget to update version
        //
        $this->author = 'Herman Tolentino MD';
        $this->version = "0.1-".date("Y-m-d");
        $this->module = "injury";
        $this->description = "CHITS Module - Injury";
    }

    // --------------- STANDARD MODULE FUNCTIONS ------------------

    function init_deps() {
    //
    // insert dependencies in module_dependencies
    //
        module::set_dep($this->module, "module");
        module::set_dep($this->module, "healthcenter");
        module::set_dep($this->module, "complaint");
        module::set_dep($this->module, "icd10");

    }

    function init_lang() {
    //
    // insert necessary language directives
    //
        module::set_lang("FTITLE_INJURY_CODE", "english", "INJURY CODE FORM", "Y");
        module::set_lang("FTITLE_CONSULT_COMPLAINT", "english", "CONSULT COMPLAINT", "Y");
        module::set_lang("LBL_COMPLAINT", "english", "COMPLAINT", "Y");
        module::set_lang("LBL_COMPLAINT_MODULE", "english", "COMPLAINT MODULE", "Y");
        module::set_lang("THEAD_MODULE", "english", "COMPLAINT MODULE", "Y");
        module::set_lang("LBL_COMPLAINT_ID", "english", "COMPLAINT ID", "Y");
        module::set_lang("LBL_COMPLAINT_NAME", "english", "COMPLAINT NAME", "Y");
        module::set_lang("FTITLE_COMPLAINT_LIST", "english", "COMPLAINT LIST", "Y");

    }

    function init_stats() {
    }

    function init_help() {
    }

    function init_menu() {
        // use this for updating menu system
        if (func_num_args()>0) {
            $arg_list = func_get_args();
        }

        // menu entries
        module::set_menu($this->module, "Injury", "STATS", "_injury_stats");
        module::set_menu($this->module, "Injury Codes", "LIBRARIES", "_injury_codes");
        module::set_menu($this->module, "Injury Locations", "LIBRARIES", "_injury_locations");
        module::set_menu($this->module, "Injury Mechanisms", "LIBRARIES", "_injury_mechanisms");

        // add more detail
        module::set_detail($this->description, $this->version, $this->author, $this->module);

    }

    function init_sql() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
        }

        // this table relates complaint to loadable modules:
        // imci_cough, imci_diarrhea, imci_fever
        module::execsql("CREATE TABLE `m_consult_injury` (".
            "`consult_id` float NOT NULL default '0',".
            "`injury_timestamp` timestamp(14) NOT NULL,".
            "`injury_id` varchar(10) NOT NULL default '',".
            "`user_id` int(11) NOT NULL default '0',".
            "`location_code` varchar(10) NOT NULL default '',".
            "`injury_time` time NOT NULL default '00:00:00',".
            "`injury_date` date NOT NULL default '0000-00-00',".
            "`mechanism_code` varchar(10) NOT NULL default '',".
            "PRIMARY KEY  (`consult_id`,`injury_timestamp`)".
            ") TYPE=InnoDB; ");

        module::execsql("CREATE TABLE `m_lib_location` (".
            "`location_id` varchar(10) NOT NULL default '',".
            "`location_name` varchar(50) NOT NULL default '',".
            "PRIMARY KEY  (`location_id`)".
            ") TYPE=InnoDB; ");

        module::execsql("CREATE TABLE `m_lib_mechanism` (".
            "`mechanism_id` varchar(10) NOT NULL default '',".
            "`mechanism_name` varchar(30) NOT NULL default '',".
            "PRIMARY KEY  (`mechanism_id`)".
            ") TYPE=InnoDB; ");

        // load initial data

    }

    function drop_tables() {
        module::execsql("DROP TABLE `m_consult_injury`;");
        module::execsql("DROP TABLE `m_lib_location`;");
        module::execsql("DROP TABLE `m_lib_mechanism`;");
    }


    // --------------- CUSTOM MODULE FUNCTIONS ------------------

    function _injury_codes() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
        }
        if ($post_vars["submitcode"]) {
            $this->process_code($menu_id,$post_vars,$get_vars,$validuser,$isadmin);
        }
        $this->display_injurycodes($menu_id,$post_vars,$get_vars,$validuser,$isadmin);
        $this->form_injurycode($menu_id,$post_vars,$get_vars,$validuser,$isadmin);
    }

    function form_injurycode() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
        }
        print "<table width='300'>";
        print "<form action = '".$_SERVER["SELF"]."?page=".$get_vars["page"]."&menu_id=$menu_id' name='form_complaint' method='post'>";
        print "<tr valign='top'><td>";
        print "<span class='library'>".FTITLE_INJURY_CODE."</span><br/><br/>";
        print "</td></tr>";
        print "<tr valign='top'><td>";
        print "<span class='boxtitle'>".LBL_INJURY_ID."</span><br> ";
        print "<input type='text' size='15' maxlength='20' class='textbox' name='injury_id' value='".($complaint["complaint_id"]?$complaint["complaint_id"]:$post_vars["complaint_id"])."' style='border: 1px solid #000000'><br>";
        print "<br/></td></tr>";
        print "<tr valign='top'><td>";
        print "<span class='boxtitle'>".LBL_INJURY_NAME."</span><br> ";
        print "<input type='text' size='15' maxlength='20' class='textbox' name='injury_name' value='".($complaint["complaint_name"]?$complaint["complaint_name"]:$post_vars["complaint_name"])."' style='border: 1px solid #000000'><br>";
        print "<br/></td></tr>";
        print "<tr><td>";
        if ($get_vars["injury_id"]) {
            print "<input type='hidden' name='injury_id' value='".$get_vars["injury_id"]."'>";
            print "<input type='submit' value = 'Update Injury Code' class='textbox' name='submitcode' style='border: 1px solid #000000'> ";
            print "<input type='submit' value = 'Delete Injury Code' class='textbox' name='submitcode' style='border: 1px solid #000000'> ";
        } else {
            print "<br><input type='submit' value = 'Add Injury Code' class='textbox' name='submitcode' style='border: 1px solid #000000'><br> ";
        }
        print "</td></tr>";
        print "</form>";
        print "</table><br>";
    }

    function process_code() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
            print_r($arg_list);
        }
        switch ($post_vars["submitcode"]) {
        case "Add Injury Code":
            break;
        }
    }

    function display_injurycodes() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
        }
    }

    function _consult_injury() {
        if (func_num_args()>0) {
            $arg_list = func_get_args();
            $menu_id = $arg_list[0];
            $post_vars = $arg_list[1];
            $get_vars = $arg_list[2];
            $validuser = $arg_list[3];
            $isadmin = $arg_list[4];
        }
        print "under development";
    }

// end of class
}
?>
